public class TimeConvert
{
   /**
      Converts military time to ordinary time.
      @param milTime, the military time provided: hhmm
      @return a string of the form 9:35 am or 7 pm
   */
   public static String militaryToOrdinaryTime(int milTime)
   {
      
      String time = milTime + "";
      int len = time.length();
      String hour = "";
      String min = "";
      if(len == 2)
      {
         int h = milTime / 10;
         if(h == 0)
         {
            return "12" + ":" + time + " " + "am";
         }
         else
            return "12" + ":" + time + " " + "am"; 
      }
      else if(len == 3)
      {
         int h = milTime / 100; 
         int f1 = milTime % 10;
         int f2 = milTime / 10 % 10;
         return h + ":" + f2 + f1 + " " + "am";
      }
      else
      {
         int h = milTime / 100;
         int f1 = milTime % 10;
         int f2 = milTime / 10 % 10;
         if(h > 12)
         {
            int h1 = h % 12;
            if(f1 == 0 && f2 == 0)
            {
               return h1 + " " + "pm";
            }
            else if(f1 != 0)
            {
               return h1 + ":" + f2 + f1 + " " + "pm";
            }
         }
      }
      return "";
   }
}